const {ccclass, property,menu} = cc._decorator;

@ccclass
@menu("自定义组件/GuassianBlur")
export default class GuassianBlur extends cc.Component {
    @property
    _bluraMount:number = 0.012;
    @property(cc.Float)
    set bluraMount(n){
        this._bluraMount = n;
        this.previwe();
    }
    get bluraMount(){
        return this._bluraMount;
    }
    private _sprite:cc.Sprite
    get sprite(){
        if(!this._sprite)
            this._sprite = this.node.getComponent(cc.Sprite);
        return this._sprite;
    }

    set blur(n){
        if(n){
            this.previwe();
        }else{
            this.sprite.setMaterial(0,cc.Material.getBuiltinMaterial('2d-sprite'));
        }
    }

    previwe(){
        if(this.bluraMount>0){
            cc.resources.load("effect/Mat/gaussianBlur", cc.Material, (err, res) => {
                if (err) {
                    cc.error(err)
                    return
                }
                this.sprite.setMaterial(0, <cc.Material>res);
                this.sprite.getMaterial(0).setProperty('bluramount',this.bluraMount);
            });
        }else{
            this.sprite.setMaterial(0,cc.Material.getBuiltinMaterial('2d-sprite'));
        }
        
    }
}
